import type { PageParams, PageResult } from '@/types/global'
import type {
  goodsListItem,
  goodsListParams,
  goodsResult,
  goodsServiceItem,
  goodsShareResult,
} from '@/types/goods'
import { request } from '@/utils/request'

/**
 * 获取商品列表
 * @param data 分页参数和商品列表查询参数
 * @returns 返回商品列表分页数据
 */
export const getGoodsListApi = (data?: PageParams & goodsListParams) => {
  return request<PageResult<goodsListItem>>({
    method: 'GET',
    url: '/goods',
    data,
  })
}

/**
 * 根据商品ID获取商品详情
 * @param id 商品ID
 * @returns 返回商品详细信息
 */
export const getGoodsByIdApi = (id: number) => {
  return request<goodsResult>({
    method: 'GET',
    url: '/goods/detail',
    data: {
      id,
    },
  })
}

/**
 * 获取商品服务信息
 * @param service_ids 服务ID字符串，多个ID用逗号分隔
 * @returns 返回商品服务列表
 */
export const getGoodsServiceApi = (service_ids: string) => {
  return request<goodsServiceItem[]>({
    method: 'GET',
    url: '/goods/service',
    data: {
      service_ids,
    },
  })
}

/**
 * 获取商品分享信息
 * @param id 商品ID
 * @returns 返回商品分享相关信息，包括分享海报等
 */
export const getShareInfoApi = (id: number) => {
  return request<goodsShareResult>({
    method: 'GET',
    url: `/goods/share?id=${id}`,
  })
}
